package model

import (
	"github.com/shopspring/decimal"
	"gorm.io/gorm"
)

// BankAccount 银行账户
type BankAccount struct {
	gorm.Model
	Sort        int     `gorm:"column:sort" form:"sort" json:"sort"`
	Bank        string  `gorm:"column:bank" form:"bank" json:"bank"`
	AccountName string  `gorm:"column:account_name" form:"accountName" json:"accountName"`
	OpeningBank string  `gorm:"column:opening_bank" form:"openingBank" json:"openingBank"`
	CardNumber  string  `gorm:"column:card_number" form:"cardNumber" json:"cardNumber"`
	Balance     float64 `gorm:"column:balance" form:"balance" json:"balance"`
	Remark      string  `gorm:"column:remark" form:"remark" json:"remark"`
}

// BankFlow 银行账户流水
type BankFlow struct {
	gorm.Model
	Date       string          `gorm:"column:date" form:"date" json:"date"` //日期
	Time       string          `gorm:"column:time" form:"time" json:"time"` //时间
	UserId     int             `gorm:"column:user_id" form:"userId" json:"userId"`
	CustomerId int             `gorm:"column:customer_id" form:"customerId" json:"customerId"`
	Customer   string          `gorm:"column:customer" form:"customer" json:"customer"`                 //客户
	AccountId  int             `gorm:"column:account_id" form:"accountId" json:"accountId"`             //银行账户Id
	Account    string          `gorm:"column:account" form:"account" json:"account"`                    //账户
	Type       string          `gorm:"column:type" form:"type" json:"type"`                             //类型：收入、支出
	Purpose    string          `gorm:"column:purpose" form:"purpose" json:"purpose"`                    //用途：
	Money      float64         `gorm:"column:money" form:"money" json:"money"`                          //金额
	Balance    decimal.Decimal `gorm:"column:balance;type:decimal(20,2)" form:"balance" json:"balance"` //账户余额
	Remark     string          `gorm:"column:remark" form:"remark" json:"remark"`                       //备注
}

// BankStatement 对账单
type BankStatement struct {
	gorm.Model
	AccountId   int     `gorm:"column:account_id" form:"accountId" json:"accountId"`     //银行账户Id
	BankFlowId  int     `gorm:"column:bank_flow_id" form:"bankFlowId" json:"bankFlowId"` //银行流水ID
	Money       float64 `gorm:"column:money" form:"money" json:"money"`                  //金额
	Function    string  `gorm:"column:function" form:"function" json:"function"`         //使用模块，找到对应的数据库
	FunctionId  int     `gorm:"column:function_id" form:"functionId" json:"functionId"`  //模块对应的收入、支出单据id
	Type        string  `gorm:"column:type" form:"type" json:"type"`                     //类型：收入、支出
	Attribute   string  `gorm:"column:attribute" form:"attribute" json:"attribute"`      //如果是采购：定金、尾款、税款、出清
	Remark      string  `gorm:"column:remark" form:"remark" json:"remark"`               //备注
	Bank        string  `gorm:"->" form:"bank" json:"bank"`                              //银行
	Date        string  `gorm:"->" form:"date" json:"date"`                              //结算日期
	AccountName string  `gorm:"->" form:"accountName" json:"accountName"`                //账户名称
	CardNumber  string  `gorm:"->" form:"cardNumber" json:"cardNumber"`                  //账户卡号

}

// BankIncomeExpense   一般费用单、其他收入
type BankIncomeExpense struct {
	gorm.Model
	Date          string          `gorm:"column:date" form:"date" json:"date"`                                                        //日期
	Type          string          `gorm:"column:type" form:"type" json:"type"`                                                        //类型：收入、支出
	Purpose       string          `gorm:"column:purpose" form:"purpose" json:"purpose"`                                               //用途：
	Money         float64         `gorm:"column:money" form:"money" json:"money"`                                                     //金额
	Balance       float64         `gorm:"column:balance" form:"balance" json:"balance"`                                               //待清算金额
	Remark        string          `gorm:"column:remark" form:"remark" json:"remark"`                                                  //备注
	BankStatement []BankStatement `gorm:"ForeignKey:FunctionId;AssociationForeignKey:Id" format:"statementList" json:"statementList"` //结算单列表
}

// BankAdjustment   调账业务
type BankAdjustment struct {
	//gorm.Model
	Date                string  `gorm:"column:date" form:"date" json:"date"` //日期
	Time                string  `gorm:"column:time" form:"time" json:"time"`
	Money               float64 `gorm:"column:money" form:"money" json:"money"`                                             //金额
	CollectionAccountId int     `gorm:"column:collection_account_id" form:"collectionAccountId" json:"collectionAccountId"` //收款方
	PaymentAccountId    int     `gorm:"column:payment_account_id" form:"paymentAccountId" json:"paymentAccountId"`          //收款方
	Remark              string  `gorm:"column:remark" form:"remark" json:"remark"`                                          //备注
	PaymentAccount      string  `gorm:"->"form:"paymentAccount" json:"paymentAccount"`                                      //收款方
	CollectionAccount   string  `gorm:"->"form:"collectionAccount" json:"collectionAccount"`                                //收款方
}
